#############################################################################
#   Copyright 2013 Stacy Doss
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#############################################################################

BITS			  = 32
CC                = g++
C-COMPILE-OPTIONS = -c -g -D_LINUX 
C-LINK-OPTIONS    = -march=i686 -Wimplicit-function-declaration -shared -m$(BITS)
#C-LINK-LIBRARIES  = -lpthread -LC:\Tcl\lib
C-LINK-LIBRARIES  = -lpthread -ltcl84
C-INCLUDE-LIST    = -I./ -IC:\Tcl\include
C-DEFINES         = -D_LINUX
#CFLAGS = -DCPLUSPLUS -g  # for use with C++ if file ext is .c
CFLAGS = 

TMPDIR	 := tmp/

DEF_OFILES   := Def.o DefComponentConnection.o DefNet.o DefPin.o DefComponent.o DefTrack.o DefGCellGrid.o Rect.o Point.o
#LEF_OFILES   := 

DIR	      := .
#DEPS	  = $(DEF_OFILES:%.o=%.d) $(LEF_OFILES:%.o=%.d)
DEPS	  = $(DEF_OFILES:%.o=%.d)

all: parse_lef_base parse_def_base parse_def

parse_lef_base: LefParserBase.yy.o LefParserBase.tab.o
	g++ -o $(CFLAGS) parse_lef_base $^

parse_def_base: DefParserBase.yy.o DefParserBase.tab.o
	g++ -o $(CFLAGS) parse_def_base $^

parse_def: DefParser.yy.o DefParser.tab.o $(DEF_OFILES)
	g++ -o $(CFLAGS) parse_def $^

LefParserBase.tab.h: LefParserBase.y
	bison -d LefParserBase.y

LefParserBase.tab.c: LefParserBase.y
	bison -d LefParserBase.y

DefParserBase.tab.h: DefParserBase.y
	bison -d DefParserBase.y

DefParserBase.tab.c: DefParserBase.y
	bison -d DefParserBase.y

DefParser.tab.h: DefParser.y
	bison -d DefParser.y

DefParser.tab.c: DefParser.y
	bison -d DefParser.y

LefParserBase.yy.c: LefParserBase.l LefParserBase.tab.h
	flex -o LefParserBase.yy.c LefParserBase.l

DefParserBase.yy.c: DefParserBase.l DefParserBase.tab.h
	flex -o DefParserBase.yy.c DefParserBase.l

DefParser.yy.c: DefParser.l DefParser.tab.h
	flex -o DefParser.yy.c DefParser.l

%.o: %.cpp
	g++ $(C-COMPILE-OPTIONS) -I./ $(C-DEFINES) $(C-INCLUDE-LIST) $<

%.d: %.cpp
	@echo Generating dependency file $@ for $<
	@rm -f $@
	@set -e; $(CXX) -MM $(C-COMPILE-OPTIONS) -I./ $(C-DEFINES) $(C-INCLUDE-LIST) $< > $@; \
	[ -s $@ ] || rm -f $@


clean:
	rm -f *.o parse_[dl]ef_base.exe parse_[dl]ef.exe [DL]efParserBase.yy.c [DL]efParser.yy.c [DL]efParserBase.tab.[ch] [DL]efParser.tab.[ch]
